module FoldersHelper
  def folder_name_value
    if action_name == "show"
      h @folder.name 
    else
      text_field :folder, :name
    end
  end

  def folder_parent_value
    if action_name == "show"
      if @folder.parent
        h @folder.parent.name
      else
        "No Parent"
      end  
    else
      select "folder", "folder_id", Folder.folder_tree(@folder.id).map { |f| [ f.qualified_name, f.id ] }, { :include_blank => true }
    end
  end

  def top_level_folders_value
    rvalue = %Q(<ul id="folders" class="sortable_elements">)

    Easel::Config.top_level_folders.each do |folder|
      rvalue << %Q{<li id="folder_#{folder.id}" ">
          <div class="li_left">#{folder.name}</div>}
      unless action_name == "show"
        rvalue << %Q{<div class="li_right">
            #{link_to('Show', folder_path(folder.id))} |
            #{link_to('Edit', edit_folder_path(folder.id))} |
            #{link_to('Destroy', folder_path(folder.id), :confirm => 'Are you sure?', :method => :delete)} 
          </div>}
      end
      rvalue << "</li>"
    end
    rvalue << "</ul>"
    unless action_name == "show"
      rvalue << sortable_element("folders", :url => {:controller => "folders", 
                                                      :action => 'sort_folders', 
                                                      :id => -1})
    end
    rvalue
  end

  def folder_content_value
    rvalue = %Q(<ul id="contents" class="sortable_elements">)
    Content.contents_for_folder(@folder.id).each do |content|
      rvalue << %Q{<li id="content_#{content.id}">
          <div class="li_left">
            #{h(content.presentable_type)}: #{h(content.name)}
          </div>}
      unless action_name == "show"
        rvalue <<  %Q{<div class="li_right"> #{links_for_content(content)} </div>}
      end
      rvalue << "</li>"
    end
    rvalue << "</ul>"
    unless action_name == "show"
      rvalue << sortable_element("contents", :url => {:controller => "folders", 
                                                      :action => 'sort_contents', 
                                                      :id => -1})
    end
    rvalue
  end
  
end
